package leetcode.weekly.week299;

import leetcode.helper.H;

//Solution3Test
public class Solution3 {
	// Solution3Test
	public int maximumsSplicedArray(int[] nums1, int[] nums2) {
		int len = nums1.length;
		long[] sums1 = new long[len + 1];
		for (int i = 1; i <= len; i++) {
			sums1[i] = nums1[i - 1] + sums1[i - 1];
		}
		int len2 = nums2.length;
		long[] sums2 = new long[len + 1];
		for (int i = 1; i <= len2; i++) {
			sums2[i] = nums2[i - 1] + sums2[i - 1];
		}
		long max = 0;
		long max1 = 0;
		for (int i = 1; i <= len; i++) {
			long dif = sums1[i] - sums2[i];
			max1 = Math.max(max1, dif + max);
			max = Math.max(max, sums2[i] - sums1[i]);
		}
		max = 0;
		long max2 = 0;
		for (int i = 1; i <= len; i++) {
			long dif = sums2[i] - sums1[i];
			max2 = Math.max(max2, dif + max);
			max = Math.max(max, sums1[i] - sums2[i]);
		}
		return (int)Math.max(sums1[len] + max2, sums2[len] + max1);
	}

}
